<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<title>2.8 常用汇编代码 | pansis.io</title>
<link rel="shortcut icon" href="https://github.pansis.site/favicon.ico">
<link href="https://github.pansis.site/styles/main.css" rel="stylesheet">
<link href="//at.alicdn.com/t/c/font_1678829_b85ccgkdqkr.css" rel="stylesheet">
<link href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css" rel="stylesheet">
<link rel="alternate" type="application/rss+xml" title="pansis.io » Feed" href="https://github.pansis.site/atom.xml">
        <meta name="description" content="1、一层for循环
C代码：
for (int i = 0; i &lt; $t0; ++i) {
  xxxx;
}

汇编代码：
li $t3,0   #i初始化
whilel_1:
      slt $s0,$t3,$t0  #循环..." />
        <meta name="keywords" content="计算机组成原理" />
        <!-- OG -->
        <meta property="og:locale" content="zh_CN">
        <meta property="og:title" content="2.8 常用汇编代码" />
        <meta property="og:type" content="article" />
        <meta property="og:description" content="1、一层for循环
C代码：
for (int i = 0; i &amp;lt; $t0; ++i) {
  xxxx;
}

汇编代码：
li $t3,0   #i初始化
whilel_1:
      slt $s0,$t3,$t0  #循环...">
        <meta property="og:url" content="https://github.pansis.site/post/2.8 常用汇编代码/" />
        <meta property="og:site_name" content="pansis.io">
        <meta property="og:updated_time" content="2024-04-05">
        <meta property="og:image" content="" />
        <meta property="og:image:secure_url" content="">
        <meta property="og:image:alt" content="2.8 常用汇编代码">
        <!-- Twitter (post.ejs) -->
        <meta name="twitter:card" content="summary_large_image">
        <meta name="twitter:title" content="2.8 常用汇编代码">
        <meta name="twitter:description" content="1、一层for循环
C代码：
for (int i = 0; i &amp;lt; $t0; ++i) {
  xxxx;
}

汇编代码：
li $t3,0   #i初始化
whilel_1:
      slt $s0,$t3,$t0  #循环...">
        <!-- <meta name="twitter:site" content="@WBoy0609">
        <meta name="twitter:creator" content="@WBoy0609"> -->
        <meta name="twitter:image" content="">
</head>

<body>
    <div class="main animated">
        <div class="header animated fadeInDown">
    <div class="site_title_container">
        <div class="site_title">
            <a href="https://github.pansis.site">pansis.io</a>
        </div>
    </div>
    <div class="my_socials">
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
        <a href="https://github.pansis.site/atom.xml" title="rss" target="_blank"><i class="iconfont icon-rss"></i></a>
    </div>
</div>

    <div class="header_menu">
        
            
                <a href="/" class="menu">首页</a>
            
        
            
                <a href="/tag/GWAaV2nvk/" class="menu">程序设计课程</a>
            
        
            
                <a href="/tag/24hangc" class="menu">比赛</a>
            
        
            
                <a href="/tag/L7r9STb75/" class="menu">Python教程</a>
            
        
            
                <a href="/tags" class="menu">分类</a>
            
        
        <div class="gridea-search-div">
            <form id="gridea-search-form" action="https://github.pansis.site/search/">
                <input class="gridea-search-input" autocomplete="off" spellcheck="false" name="q"/>
            </form>
        </div>
    </div>

            <div class="autopagerize_page_element">
                <div class="content">
                    <div class="post_page">
                        <div class="post animated fadeInDown">
                            <div class="post_title post_detail_title">
                                <h2>
                                    2.8 常用汇编代码
                                </h2>
                                <span class="article-info">
                                    2024-04-05, 168 words, 1 min read
                                </span>
                            </div>
                            <div class="post_content markdown">
                                <p class="md_block">
                                    <span class="md_line md_line_start md_line_end">
                                        <h4 id="1-一层for循环">1、一层for循环</h4>
<p>C代码：</p>
<pre><code class="language-c">for (int i = 0; i &lt; $t0; ++i) {
  xxxx;
}
</code></pre>
<p>汇编代码：</p>
<pre><code class="language-assembly">li $t3,0   #i初始化
whilel_1:
      slt $s0,$t3,$t0  #循环条件判断
      bne $s0,1,endwhile_1
      #循环主体代码
      
      #循环主体代码结束
      midwhile_1:
        addi $t3,$t3,1  #for循环结束的内容
        j while_1
endwhile1_1:
</code></pre>
<h4 id="2-两层for循环">2、两层for循环</h4>
<p>C代码</p>
<pre><code class="language-c">for (int i = 0; i &lt; $t0; ++i) {
        for (int j = 0; j &lt; $t0; ++j) {
            
        }
}
</code></pre>
<p>汇编代码</p>
<pre><code class="language-assembly">li $t3,0   #i初始化
li $t4,0   #j初始化
while_1_1:
   slt $s0,$t3,$t0
   bne $s0,1,endwhile_1_1
   li $t4,0
   while_1_2:
      slt $s0,$t4,$t0
      bne $s0,1,endwhile_1_2
      #循环主体代码
      
      #循环主体代码结束
      midwhile_1_2:
      	addi $t4,$t4,1
      	j while_1_2
      endwhile_1_2:
   midwhile_1_1:
      addi $t3,$t3,1
      j while_1_1
endwhile_1_1:
</code></pre>
<br />
                                            
                                </p>
                            </div>
                            <div class="post_footer">
                                
                                    <div class="meta">
                                        <div class="info"><span class="field tags"><i class="iconfont icon-tag-sm"></i>
                                                
                                                    <a href="https://github.pansis.site/tag/jsjzcyl/" class="article-info">
                                                        计算机组成原理
                                                    </a>
                                                    
                                            </span>
                                        </div>
                                    </div>
                                    
                                        
                            </div>
                        </div>
                        
                            
                                <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
<div id="gitalk-container" style="padding-bottom: 20px;"></div>
<script>
    var pageId = (location.pathname).substring(1, 49) // Ensure uniqueness and length less than 50
    pageId = pageId.endsWith('/') ? pageId.slice(0, -1) : pageId // 以斜杠结尾则去除
    var gitalk = new Gitalk({
        clientID: '9d5eba33618472c44a07',
        clientSecret: '065a85ed04333ceebfc4f01d7ca1674175730339',
        repo: 'fzxl2003.github.io',
        owner: 'fzxl2003',
        admin: ['fzxl2003'],
        id: pageId,
        distractionFreeMode: false  // Facebook-like distraction free mode
    })
    gitalk.render('gitalk-container')
</script>
                                    
                                        
                                                    
                    </div>
                </div>
            </div>
    </div>
    <div class="footer">
    
    <div class="powered_by">
        <a href="https://codeberg.org/kytrun/gridea-theme-one" target="_blank">Theme One,</a>
        <a href="https://open.gridea.dev/" target="_blank">Powered by Gridea&#65281;</a>
    </div>
    
    
        <div class="footer_slogan">
            Powered by <a href="https://github.com/getgridea/gridea" target="_blank">Gridea</a>
        </div>
    
    <div id="back_to_top" class="back_to_top">
        <span>△</span>
    </div>
    
</div>

<script src="https://github.pansis.site/media/scripts/util.js"></script>
        <link rel="stylesheet" href="//unpkg.com/@highlightjs/cdn-assets@11.5.1/styles/default.min.css">
        <script src="//unpkg.com/@highlightjs/cdn-assets@11.5.1/highlight.min.js"></script>
        <script>hljs.highlightAll();</script>
</body>

</html>